{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "18b90df8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import matplotlib.pyplot as plt\n",
    "from sklearn.datasets import fetch_openml\n",
    "from sklearn.neural_network import MLPClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "57b7b0cb",
   "metadata": {},
   "outputs": [],
   "source": [
    "X, y = fetch_openml('Fashion-MNIST', version=1, return_X_y=True)\n",
    "\n",
    "X = X / 255\n",
    "\n",
    "# use the traditional train/test split\n",
    "X_train, X_test = X[:60000], X[60000:]\n",
    "y_train, y_test = y[:60000], y[60000:]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "dde8b979",
   "metadata": {},
   "outputs": [],
   "source": [
    "mlp = MLPClassifier(hidden_layer_sizes=(50), max_iter=10, alpha=1e-4, \n",
    "                    solver='sgd', verbose=10, random_state=1, learning_rate_init=.1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "963e9392",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration 1, loss = 0.53238440\n",
      "Iteration 2, loss = 0.39300993\n",
      "Iteration 3, loss = 0.35940922\n",
      "Iteration 4, loss = 0.34054618\n",
      "Iteration 5, loss = 0.32284530\n",
      "Iteration 6, loss = 0.31124182\n",
      "Iteration 7, loss = 0.30183898\n",
      "Iteration 8, loss = 0.29540012\n",
      "Iteration 9, loss = 0.28711181\n",
      "Iteration 10, loss = 0.27971370\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "D:\\development\\Anaconda3\\envs\\pytorch\\lib\\site-packages\\sklearn\\neural_network\\_multilayer_perceptron.py:696: ConvergenceWarning: Stochastic Optimizer: Maximum iterations (10) reached and the optimization hasn't converged yet.\n",
      "  ConvergenceWarning,\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "MLPClassifier(hidden_layer_sizes=50, learning_rate_init=0.1, max_iter=10,\n",
       "              random_state=1, solver='sgd', verbose=10)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "mlp.fit(X_train, y_train)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "23f3a9e4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Training set score: 0.903\n",
      "Test set score: 0.867\n"
     ]
    }
   ],
   "source": [
    "print(f\"Training set score: {mlp.score(X_train, y_train):.3f}\")\n",
    "print(f\"Test set score: {mlp.score(X_test, y_test):.3f}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d988ce8e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
